home *** CD-ROM | disk | FTP | other *** search
- /* TEXT Hook.c is a rather cheap, nevertheless illustrative, example of
- a Preview hook for Locare 1.9 or above. This hook is enabled for
- files of type TEXT. It just reads the first 2000 (or less if the
- file is shorter) characters of a matched file and displays as much
- as it can in a window. The user clicks to exit the preview hook.
-
-
- Written in LightspeedC from THINK Technologies, Inc.
-
-
- Feel free to use this as an example or a foundation for your own
- endeavors. If you wish to improve upon this, go right ahead.
-
- NOTE: This hook is messy. It is meant to serve as an example.
- It is functional as is, but it could be much better… More defenses
- could be used.
- */
-
-
-
-
- #include <EventMgr.h>
- #include <MacTypes.h>
- #include <FileMgr.h>
- #include <FontMgr.h>
- #include <WindowMgr.h>
-
- typedef struct
- { char version; /* 1 for now */
- char message;
- int volume;
- long directory;
- int index;
- } PreviewRec;
-
-
- pascal void main(infoPtr)
- PreviewRec *infoPtr;
- { char nameString[256];
- ParamBlockRec myHRec;
- WindowPtr myWin;
- Rect rect;
- char Buffer[2000]; /* 2000 byte buffer */
-
- myHRec.fileParam.ioFDirIndex = infoPtr->index;
- myHRec.fileParam.ioFlNum = infoPtr->directory;
- myHRec.fileParam.ioVRefNum = infoPtr->volume;
- myHRec.fileParam.ioNamePtr = (StringPtr)nameString;
- PBGetCatInfo(&myHRec,FALSE);
-
- myHRec.fileParam.ioFlNum = infoPtr->directory;
- myHRec.fileParam.ioVRefNum = infoPtr->volume;
- myHRec.fileParam.ioNamePtr = (StringPtr)nameString;
- myHRec.fileParam.filler1 = fsRdPerm; /* LS C's file mgr header
- doesn't offer much support for H Rec's....ioParam offers none.
- I have modified my own header to include H rec's, but maybe
- you haven't. So I just used the available fileParam, where
- filler1 = ioPermssn byte. */
- myHRec.fileParam.ioFDirIndex = 0;
- PBHOpen(&myHRec,FALSE);
- rect.top = 41;
- rect.left = 11;
- rect.right = rect.left + 490;
- rect.bottom = rect.top + 300;
-
- myWin = NewWindow(0L,&rect,nameString,TRUE,noGrowDocProc,-1L,FALSE,0L);
- SetPort(myWin);
-
- myHRec.ioParam.ioPosMode = fsFromStart;
- myHRec.ioParam.ioBuffer = Buffer;
- myHRec.ioParam.ioPosOffset = 0;
- myHRec.ioParam.ioReqCount = 2000;
- PBRead(&myHRec,FALSE);
-
- TextSize(9);
- TextFont(monaco);
- rect.top = 1;
- rect.left = 2;
- rect.right = rect.left + 488;
- rect.bottom = rect.top + 285;
- TextBox(Buffer,myHRec.ioParam.ioActCount,&rect,0);
- MoveTo(0,286);
- LineTo(490,286);
-
- MoveTo(5,298);
- DrawString("\p'TEXT' file preview hook by Raymond Lau. \
- Please <CLICK> to continue…");
- do
- {}
- while(!Button());
- FlushEvents(mDownMask,0l);
-
- DisposeWindow(myWin);
-
-
- PBClose(&myHRec,FALSE);
- infoPtr->message = 1;
- return;
- }